﻿namespace PowerSong.UserInterface
    {
    using System.Windows.Controls;
    using System.Windows;
    using PowerSong.SongDatabase;
    using System.Windows.Media;

    /// <summary>
    /// Interaction logic for SubStylePreview.xaml
    /// </summary>
    public partial class SubStylePreview : UserControl
        {

        public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(SubStylePreview), new PropertyMetadata(HandleTextChanged));

        public string Text
            {
            get
                {
                return (string)GetValue(TextProperty);
                }
            set
                {
                SetValue(TextProperty, value);
                }
            }

        private static void HandleTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
            ((SubStylePreview)d).TextBlock.Text = (string)e.NewValue;
            }

        public SubStylePreview()
            {
            InitializeComponent();
            }

        public void SetSubStyle(Color background, SubStyle style)
            {

            // Set font
            TextBlock.FontFamily = new FontFamily(style.FontName);

            // Set bold
            TextBlock.FontWeight = FontWeights.Regular;
            if ((style.FontStyle & FontEffectType.Bold) == FontEffectType.Bold) TextBlock.FontWeight = FontWeights.Bold;

            // Set italic
            TextBlock.FontStyle = FontStyles.Normal;
            if ((style.FontStyle & FontEffectType.Italic) == FontEffectType.Italic) TextBlock.FontWeight = FontWeights.Bold;

            // Set underline
            TextBlock.TextDecorations = null;
            if ((style.FontStyle & FontEffectType.Underline) == FontEffectType.Underline) TextBlock.TextDecorations = TextDecorations.Underline;

            // Set underline
            TextBlock.FontWeight = FontWeights.Regular;
            if (style.FontStyle == FontEffectType.Bold) TextBlock.FontWeight = FontWeights.Bold;

            // Set text colour
            TextBlock.Foreground = new SolidColorBrush(style.FontColor.ToColor());

            // Set background
            Border.Background = new SolidColorBrush(background);
            if (style.FontEffect == TextEffectType.FillRectangle) Border.Background = new SolidColorBrush(style.FontEffectColor.ToColor());

            // Set horizontal alignment
            if (style.TextAlignment == Alignment.LeftBottom ||
                style.TextAlignment == Alignment.LeftMiddle ||
                style.TextAlignment == Alignment.LeftTop)
                {
                TextBlock.HorizontalAlignment = HorizontalAlignment.Left;
                }
            if (style.TextAlignment == Alignment.CenterBottom ||
                style.TextAlignment == Alignment.CenterMiddle ||
                style.TextAlignment == Alignment.CenterTop)
                {
                TextBlock.HorizontalAlignment = HorizontalAlignment.Center;
                }
            if (style.TextAlignment == Alignment.RightBottom ||
                style.TextAlignment == Alignment.RightMiddle ||
                style.TextAlignment == Alignment.RightTop)
                {
                TextBlock.HorizontalAlignment = HorizontalAlignment.Right;
                }

            
            }

        }

    }
